package com.sunday.common.core.converter;

import com.sunday.common.core.utils.DateTimeUtils;
import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.converter.BidirectionalConverter;
import ma.glasnost.orika.metadata.Type;

import java.time.LocalDateTime;

/**
 * 时间类型转换 LocalDateTime <-> String
 *
 * @author zsy
 * @since 2022/10/13
 */
public class DateTypeConverter extends BidirectionalConverter<LocalDateTime, String> {

    @Override
    public String convertTo(LocalDateTime source, Type<String> destinationType, MappingContext mappingContext) {
        return DateTimeUtils.formatDateTimeSplit(source);
    }

    @Override
    public LocalDateTime convertFrom(String source, Type<LocalDateTime> destinationType, MappingContext mappingContext) {
        return DateTimeUtils.convertDateTimeSplit(source);
    }

}
